package com.jketing.entity.ams.base;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.jketing.annotation.FieldMeta;
import com.jketing.entity.ams.sys.Dictionary;

/**
 * Employee 职工实体
 * 
 * @author  李荣华
 * @version v1.0
 * @date     2017-08-16
 * @since   JPA 2.1
 */
@Entity
@Table(name = "Employee_")
public class Employee extends Person {
	private static final long serialVersionUID = 4390502470873570811L;
	/**
	 * organ:当前部门
	 */
	private Organ organ;
	/**
	 * organs:所属部门
	 */
	@FieldMeta(name="Entity:organs",explain="所属机构")  
	private Set<Organ> organs = new HashSet<Organ>();
	/**
	 * code:工号
	 */
	@FieldMeta(name="String:code",explain="职工编号") 
	private String code;    
	/**
	 * photo:照片
	 */
	private byte[] photo;
	/**
	 * educationalBackground:学历
	 */
	@FieldMeta(name="Entity:educationalBackground",explain="学历") 
	private Dictionary educationalBackground; 
	/**
	 * school:毕业院校
	 */
	@FieldMeta(name="String:school",explain="毕业院校") 
	private String school; 
	/**
	 * speciality:所学专业
	 */
	@FieldMeta(name="String:speciality",explain="所学专业")	
	private String speciality; 		
	/**
	 * qualification:职称
	 */
	@FieldMeta(name="Entity:qualification",explain="职称") 
	private Dictionary qualification; 	
	/**
	 * duty:职务
	 */
	@FieldMeta(name="Entity:duty",explain="职务") 
	private Dictionary duty;
	
	/**
	 * organ 当前部门(员工当前所在部门，其它部门切换)
	 */
	@ManyToOne
	@JoinColumn(name = "organId")
	public Organ getOrgan() {
		return organ;
	}
	public void setOrgan(Organ organ) {
		this.organ = organ;
	}
	
	/**
	 * organs 所属组织机构集合(一个员工可在多个部门)
	 */
	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.LAZY)
	@JoinTable(name = "EmployeeMapOrgan", joinColumns = { @JoinColumn(name = "EmployeeId") }, inverseJoinColumns = { @JoinColumn(name = "OrganId") })
	public Set<Organ> getOrgans() {
		return organs;
	}
	public void setOrgans(Set<Organ> organs) {
		this.organs = organs;
	}
	
	/**
	 * 增加机构
	 * @param entity
	 */
	public void add(Organ entity){
		if (!this.organs.contains(entity)) {
			this.organs.add(entity);
		}
	}
	
	/**
	 * 删除机构
	 * @param entity
	 */
	public void remove(Organ entity){
		if (this.organs.contains(entity)) {
			this.organs.remove(entity);
		}
	}
	
	/**
	 * 员工工号/编号
	 */
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	
	/**
	 * 照片
	 */
	@Lob
	public byte[] getPhoto() {
		return photo;
	}
	public void setPhoto(byte[] photo) {
		this.photo = photo;
	}
	
	/**
	 * 学历
	 */
	@ManyToOne
	@JoinColumn(name = "educationalBackgroundId")
	public Dictionary getEducationalBackground() {
		return educationalBackground;
	}
	public void setEducationalBackground(Dictionary educationalBackground) {
		this.educationalBackground = educationalBackground;
	}

	/**
	 * 毕业学校
	 */
	public String getSchool() {
		return school;
	}	
	public void setSchool(String school) {
		this.school = school;
	}

	/**
	 * 专业
	 */
	public String getSpeciality() {
		return speciality;
	}
	public void setSpeciality(String speciality) {
		this.speciality = speciality;
	}
	
	/**
	 * qualification 职称
	 */
	@ManyToOne
	@JoinColumn(name = "qualificationId")
	public Dictionary getQualification() {
		return qualification;
	}
	public void setQualification(Dictionary qualification) {
		this.qualification = qualification;
	}
	
	/**
	 * duty 职务
	 */
	@ManyToOne
	@JoinColumn(name = "dutyId")
	public Dictionary getDuty() {
		return duty;
	}
	public void setDuty(Dictionary duty) {
		this.duty = duty;
	}
}
